package com.xiaoyu.lanling.feature.invite.data

import `in`.srain.cube.request.JsonData
import `in`.srain.cube.request.RequestDefaultHandler
import com.xiaoyu.base.net.RequestCreator
import com.xiaoyu.lanling.common.config.HttpConfig
import com.xiaoyu.lanling.event.invite.InvitationWithDrawListEvent
import com.xiaoyu.lanling.event.invite.InviteShareInfoEvent
import com.xiaoyu.lanling.event.invite.InviteTipEvent
import com.xiaoyu.lanling.event.invite.OtherWithdrawEvent
import com.xiaoyu.lanling.event.invite.list.InviteEarnInfoEvent

object InviteData {

    fun getInviteTip(requestTag: Any) {
        RequestCreator.create<InviteTipEvent>(requestTag, InviteTipEvent::class.java)
                .setRequestUrl(HttpConfig.LANLING_INVITE_TIP)
                .enqueue()
    }

    fun getInviteEarnInfo(requestTag: Any) {
        RequestCreator.create<InviteEarnInfoEvent>(requestTag, InviteEarnInfoEvent::class.java)
                .setRequestUrl(HttpConfig.LANLING_INVITE_EARN_INFO)
                .enqueue()
    }

    fun getInviteShareInfo(requestTag: Any) {
        RequestCreator.create<InviteShareInfoEvent>(requestTag, InviteShareInfoEvent::class.java)
                .setRequestUrl(HttpConfig.LANLING_INVITE_SHARE_INFO)
                .enqueue()
    }

    fun getInvitationBannerWithDrawList(requestTag: Any) {
        RequestCreator.create<InvitationWithDrawListEvent>(InvitationWithDrawListEvent::class.java)
                .setRequestUrl(HttpConfig.LANLING_INVITE_WITHDRAW_BANNER_LIST)
                .setRequestHandler(object : RequestDefaultHandler<InvitationWithDrawListEvent, JsonData>() {
                    override fun processOriginData(originData: JsonData): InvitationWithDrawListEvent {
                        return InvitationWithDrawListEvent(requestTag, originData)
                    }

                    override fun onRequestFinish(event: InvitationWithDrawListEvent?) {
                        event?.post()
                    }
                })
                .enqueue()
    }

    fun getOtherWithDrawMessage(requestTag: Any) {
        RequestCreator.create<OtherWithdrawEvent>(requestTag, OtherWithdrawEvent::class.java)
                .setRequestUrl(HttpConfig.LANLING_INVITE_OTHER_WITHDRAW_MESSAGE)
                .enqueue()
    }
}